package com.testmanager.testmananger.others;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;

import java.net.SocketTimeoutException;
import java.util.Scanner;

public class SZJKJSONParse {

    public static String getValue(String fileText,String expression){
       // JSONObject json = strToJsonOfJufan(fileText);
    return  null;
    }

    public static void setValue(String fileText,String expression,String value){

    }

    public static JSONObject strToJsonOfJufan(String content){
        JSONObject contentObject = JSONObject.parseObject(content);
        String tempstr = "";
        JSONObject tempJson = null;
        JSONObject contentdataType = new JSONObject();
        for (String key : contentObject.keySet()){
            tempJson = JSONObject.parseObject(contentObject.getString(key));
            contentdataType.put(key,tempJson.getString("dataType"));
              tempstr = tempJson.getString("data");


            contentObject.put(key, isJsonValid(tempstr)?JSONObject.parseObject(tempstr):tempstr);
        }
        contentObject.put("dataType",contentdataType);

        return contentObject;
    }

    private static boolean isJsonValid(String s){
        try {
            JSONObject.parseObject(s);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    public static String jsonToStrOfJufan(JSONObject json){
        JSONObject newjson = new JSONObject();
       // System.out.println(json.keySet().size());
        for (String key : json.keySet()){
            if ("dataType".equals(key)) continue;
            JSONObject data = new JSONObject();
            data.put("data",json.getString(key));
            data.put("dataType",json.getJSONObject("dataType").getString(key));
            newjson.put(key,data.toJSONString());
        }
        return newjson.toJSONString();
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String json = scanner.nextLine();
        System.out.println(JSONObject.parse(json));
       // System.out.println(strToJsonOfJufan(json));
       System.out.println(jsonToStrOfJufan(strToJsonOfJufan(json)));
    }
}
